﻿using MediatR;
using SystemMHB.API.Application.Command.ReturnWarehouseCommand;
using SystemMHB.Infrstructer.Interface;

namespace SystemMHB.API.Application.CommandHandlers.ReturnWarehouseCommandHandler
{
    public class ReturnWarehouseAddCommandHandler : IRequestHandler<ReturnWarehouseAddCommand, int>
    {
        /// <summary>
        /// 返库信息
        /// </summary>
        IReturnWarehouseRepository repository;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="repository"></param>
        public ReturnWarehouseAddCommandHandler(IReturnWarehouseRepository repository)
        {
            this.repository = repository;
        }

        public async Task<int> Handle(ReturnWarehouseAddCommand request, CancellationToken cancellationToken)
        {
            request.AddName = "张三";
            request.AddTime = DateTime.Now.ToUniversalTime();
            request.IsDel = false;
            return await repository.AddAsync(new Domian.ReturnWarehouse
            {
                rWId = request.rWId,
                returnWarehouseNumber = request.returnWarehouseNumber,
                outboundNumber = request.outboundNumber,
                outboundQuantity = request.outboundQuantity,
                MaterialNumber = request.MaterialNumber,
                rawMaterialName = request.rawMaterialName,
                rawMaterialLotNumber = request.rawMaterialLotNumber,
                returnWarehouseQuantity = request.returnWarehouseQuantity,
                returnStatus = request.returnStatus,
                returnWarehouseCause=request.returnWarehouseCause,
                IsDel = request.IsDel,
                AddName = request.AddName,
                AddTime = request.AddTime
            });
        }
    }
}
